import os 
import cv2
path=r'E:\zhujinchao\uterus\cellseg'
for i in os.listdir(path):
    ipath=os.path.join(path,i)
    # print(ipath)
    tpath=ipath+'\\'+'train'
    mpath=ipath+'\\'+'trainmask'
    list1=[]
    for img in os.listdir(mpath):
        list1.append(img)
    for i2 in os.listdir(tpath):
        if i2 not in list1:
            t2img=os.path.join(tpath,i2)
            os.remove(t2img)